package com.example.testone.receiver

import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.example.testone.MainActivity

class EventReceiver: BroadcastReceiver() {

    @SuppressLint("UnsafeProtectedBroadcastReceiver")
    override fun onReceive(context: Context?, intent: Intent?) {
        var state = "no"
        if(intent?.action.equals("android.intent.action.BOOT_COMPLETED")){
            state = "yes"

            val i = Intent(context, MainActivity::class.java)
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            context?.startActivity(i)
        }

        val sharedPref = context!!.getSharedPreferences("preference_file_key", Context.MODE_PRIVATE)
        with(sharedPref!!.edit()){
            putString("testShareDataInfo", state)
            commit()
        }
    }

}